home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************************
-
- mini.windows.c
-
- ***********************************************************************************/
-
- /* NEEDED TO DEFINE NEW TEXTEDIT ROUTINES IN TEXTEDIT.H */
- #define __ALLNU__
-
- #include <QuickDraw.h>
- #include <Types.h>
- #include <Windows.h>
- #include <TextEdit.h>
- #include <Controls.h>
- #include <Events.h>
- #include <fonts.h>
- #include <toolutils.h>
- #include <memory.h>
-
- #include "MiniEdit.h"
-
- extern WindowRecord wRecord;
- extern WindowPtr myWindow;
- extern ControlHandle vScroll;
- extern TEHandle TEH;
- extern char dirty;
- extern Str255 theFileName;
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- SetUpWindows()
- {
- Rect viewRect;
- Rect vScrollRect;
- TextStyle Styl;
-
- myWindow = GetNewWindow( windowID,(Ptr)&wRecord, (WindowPtr)-1L );
- SetPort(myWindow);
-
- vScrollRect = (*myWindow).portRect;
- vScrollRect.left = vScrollRect.right-15;
- vScrollRect.right += 1;
- vScrollRect.bottom -= 14;
- vScrollRect.top -= 1;
- vScroll = NewControl(myWindow, &vScrollRect,
- "", 1, 0, 0, 0,
- scrollBarProc, 0L);
-
- viewRect = qd.thePort->portRect;
- viewRect.right -= SBarWidth;
- viewRect.bottom -= SBarWidth;
- InsetRect(&viewRect, 4, 4);
-
- TEH = TEStylNew( &viewRect, &viewRect );
- Styl.tsFont = newYork;
- Styl.tsSize = 14;
- TESetStyle(doSize+doFont,&Styl,1,TEH);
-
- SetView(qd.thePort);
- dirty = 0;
- }
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- AdjustText ()
- {
- int oldScroll, newScroll, delta, value, i;
- register LHPtr LHptr;
-
- oldScroll = (**TEH).viewRect.top - (**TEH).destRect.top;
-
- newScroll = 0;
- value = GetCtlValue(vScroll);
- LHptr = *(**GetStylHandle(TEH)).lhTab;
- for (i=0;i<value;i++)
- newScroll += LHptr[i].lhHeight;
-
- delta = oldScroll - newScroll;
-
- if (delta != 0)
- TEScroll(0, delta, TEH);
- }
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- SetVScroll()
- {
- short lines, viewLines, max;
- short oldValue, oldMax;
- TEPtr te;
-
- oldValue = GetCtlValue(vScroll);
- oldMax = GetCtlMax(vScroll);
-
- te = *TEH; /* point to TERec for convenience */
-
- lines = te->nLines;
- viewLines = linesInView(TEH,0);
-
- /* since nLines isn’t right if the last character is a return, check for that case */
- if ( *(*te->hText + te->teLength - 1) == '\r' )
- lines += 1;
- max = lines - viewLines;
-
- if ( max < 0 ) max = 0;
- SetCtlMax(vScroll, max);
- }
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- ShowSelect()
- {
- register int topLine, bottomLine, theLine, lines;
- int before,selStart;
- short *lStarts;
-
- // SetVScroll();
- // AdjustText();
-
- lines = linesInView(TEH,&before);
-
- topLine = GetCtlValue(vScroll);
- bottomLine = topLine + lines;
-
- selStart = (**TEH).selStart;
- lStarts = (**TEH).lineStarts;
-
- if ((selStart < lStarts[topLine]) || (selStart > lStarts[bottomLine]))
- {
- SetVScroll();
-
- for (theLine = 0, lStarts = (**TEH).lineStarts;
- lStarts[theLine] < selStart;
- theLine++)
- ;
-
- SetCtlValue(vScroll, theLine - before + lines / 2);
- AdjustText();
- }
- }
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- linesInView(TEHdl,above)
- TEHandle TEHdl;
- int *above;
- {
- register LHHandle LHHdl;
- register LHPtr LHptr;
- register int nLines,before,within;
- Rect dest,view;
-
- dest = (**TEHdl).destRect;
- view = (**TEHdl).viewRect;
-
- LHHdl = (**GetStylHandle(TEHdl)).lhTab;
- nLines = (**TEHdl).nLines;
- before = 0;
-
- LHptr = *LHHdl;
-
- while ((dest.top < view.top) && (before < nLines))
- dest.top += LHptr[before++].lhHeight;
-
- within = before;
- view.bottom--;
-
- while ((dest.top < view.bottom) && (within < nLines))
- dest.top += LHptr[within++].lhHeight;
-
- if (above) *above = before;
- within -= before;
-
- return(within);
- }
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- SetView(w)
- WindowPtr w;
- {
- (**TEH).viewRect = w->portRect;
- (**TEH).viewRect.right -= SBarWidth;
- (**TEH).viewRect.bottom -= SBarWidth;
- InsetRect(&(**TEH).viewRect, 4, 4);
-
- (**TEH).destRect.right = (**TEH).viewRect.right;
-
- TECalText(TEH);
- }
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- UpdateWindow(theWindow)
- WindowPtr theWindow;
- {
- GrafPtr savePort;
-
- GetPort( &savePort );
- SetPort( theWindow );
-
- BeginUpdate( theWindow );
- EraseRect(&theWindow->portRect);
- DrawControls( theWindow );
- DrawGrowIcon( theWindow );
- TEUpdate( &theWindow->portRect, TEH );
- EndUpdate( theWindow );
-
- SetPort( savePort );
- }
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- pascal void ScrollProc(theControl, theCode)
- ControlHandle theControl;
- short theCode;
- {
- int pageSize;
- int scrollAmt;
- int lines;
-
- if (theCode == 0)
- return;
-
- lines = linesInView(TEH,NULL);
-
- pageSize = lines - 1;
-
- switch (theCode)
- {
- case inUpButton:
- scrollAmt = -1;
- break;
- case inDownButton:
- scrollAmt = 1;
- break;
- case inPageUp:
- scrollAmt = -pageSize;
- break;
- case inPageDown:
- scrollAmt = pageSize;
- break;
- }
-
- SetCtlValue( theControl, GetCtlValue(theControl)+scrollAmt );
- AdjustText();
-
- }
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- DoContent(theWindow, theEvent)
- WindowPtr theWindow;
- EventRecord *theEvent;
- {
- int cntlCode;
- ControlHandle theControl;
- GrafPtr savePort;
-
- GetPort(&savePort);
- SetPort(theWindow);
- GlobalToLocal( &theEvent->where );
-
- cntlCode = FindControl(theEvent->where, theWindow, &theControl);
- if (cntlCode == 0)
- {
- if (PtInRect( theEvent->where, &(**TEH).viewRect ))
- TEClick( theEvent->where, (theEvent->modifiers & shiftKey )!=0, TEH);
- }
- else
- if (cntlCode == inThumb)
- {
- TrackControl(theControl, theEvent->where, 0L);
- AdjustText();
- }
- else
- TrackControl(theControl, theEvent->where, (ProcPtr)ScrollProc);
-
- SetPort(savePort);
- }
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- MyGrowWindow( w, p )
- WindowPtr w;
- Point p;
- {
- GrafPtr savePort;
- long theResult;
- int oScroll,b,r;
- Rect rct, oView;
-
- GetPort( &savePort );
- SetPort( w );
-
- b = qd.screenBits.bounds.bottom;
- r = qd.screenBits.bounds.right;
-
- SetRect(&rct, 100, 100, r, b);
- theResult = GrowWindow( w, p, &rct );
-
- if (theResult == 0)
- return;
-
- SizeWindow( w, LoWord(theResult), HiWord(theResult), 1);
-
- InvalRect(&w->portRect);
- oView = (**TEH).viewRect;
- oScroll = GetCtlValue(vScroll);
-
- SetView(w);
- HidePen();
- MoveControl(vScroll,
- w->portRect.right - SBarWidth,
- w->portRect.top-1);
- SizeControl(vScroll,
- SBarWidth+1,
- w->portRect.bottom - w->portRect.top-(SBarWidth-2));
- ShowPen();
-
- SetVScroll();
- AdjustText();
-
- SetPort( savePort );
- }
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
- CloseMyWindow()
- {
- HideWindow( myWindow );
- TESetSelect( 0, (**TEH).teLength, TEH );
- TEDelete( TEH );
- SetVScroll();
- }
-
- /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
-
-